package pt.iscte.pcd.banquet;

public class Table {

	public static final int CAPACITY = 10;
	private int n = -1;
	Boar[] javalis = new Boar[CAPACITY];
	
	public synchronized Boar get() {
		while (n < 0) { // < 1
			try {
				wait();
			} catch (InterruptedException e) {
			}			
		}		
		n--;
		notifyAll();
		return javalis[n + 1];
	}

	public synchronized void put(Boar javali) {
		while (n == CAPACITY) { // >= CAPACITY
			try {
				wait();
			} catch (InterruptedException e) {
			}			
		}		
		n++;
		javalis[n] = javali;
		notifyAll();
	}
	
}
